/*
 * @Description:: 请补充填写
 * @Version: 1.0
 * @Author: 小白
 * @Date: 2025-07-18 10:44:49
 * @LastEditors: 小白
 * @LastEditTime: 2025-11-10 17:11:57
 * @FilePath: \jzadmin\src\router\index.ts
 */
import { store } from '@/store/index';
/*
 * @Author: your name
 * @Date: 2022-03-13 08:57:33
 * @LastEditTime: 2025-07-21 14:12:41
 * @LastEditors: 小白
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \tms-admin\src\router\index.ts
 */
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import Main from '@/layout/Main.vue'
// import Main from '../layout/secondMain.vue'
import nprogress from 'nprogress'
import { getToken } from '../plugins/cookie'
import 'nprogress/nprogress.css'
const routes: RouteRecordRaw[] = [
  {
    path: '/',
    component: Main,
    children: [
      {
        path: '/', // 默认子路由
        name: '轮播图管理',
        component: () => import('../views/home/index.vue'),
        meta: {
          // ion-ios-location
          icon: 'ion-image',
          title: '轮播图管理',
          isHidden: false,
        },
      },
     {
        path: '/service', // 默认子路由
        name: '服务管理',
        meta: {
          // ion-ios-location
          icon: 'ion-document-text',
          title: '服务管理',
          isHidden: false,
        },
        children: [
          {
            path: '/service/type',
             name: '服务分类',
            component: () => import('../views/service_management/service_type/index.vue'),
            meta: {
              title: '服务分类',
              isHidden: false,
            }
          },
          {
            path: '/service/list',
             name: '服务列表',
            component: () => import('../views/service_management/service_list/index.vue'),
            meta: {
              title: '服务列表',
              isHidden: false,
            }
          },
        ]
      },
      {
        path: '/product',
             name: '商品管理',
            component: () => import('../views/product_list/index.vue'),
            meta: {
              title: '商品管理',
              //  icon: 'ion-paper-airplane',
               icon: 'ion-laptop',

              isHidden: false,
            }
      },
      {
        path: '/vip', // 默认子路由
        name: '会员管理',
        meta: {
          icon: 'ion-person-stalker',
          title: '会员管理',
          isHidden: false,
        },
        children:[
           {
            path: '/vip/grade',
             name: '会员等级',
            component: () => import('../views/vip_management/vip_grade/index.vue'),
            meta: {
              title: '会员等级',
              isHidden: false,
            }
          },
         {
            path: '/vip/list',
             name: '会员列表',
            component: () => import('../views/vip_management/vip_list/index.vue'),
            meta: {
              title: '会员列表',
              isHidden: false,
            }
          },
          {
            path: '/vip/rules',
             name: '积分规则',
            component: () => import('../views/vip_management/points_rules/index.vue'),
            meta: {
              title: '积分规则',
              isHidden: false,
            }
          },
        ]
      },
       {
        path: '/users', // 默认子路由
        name: '用户管理',
        component: () => import('../views/users/index.vue'),
        meta: {
          icon: ' ion-person',
          title: '用户管理',
          isHidden: false,
        },
      },
      {
        path: '/order', // 默认子路由
        name: '订单管理',
        meta: {
          icon: 'ion-ios-paper',
          title: '订单管理',
          isHidden: false,
        },
         children:[
         {
            path: '/order/service',
             name: '服务订单',
            component: () => import('../views/order_management/serice_order/index.vue'),
            meta: {
              title: '服务订单',
              isHidden: false,
            }
          },
          {
            path: '/order/product',
             name: '商品订单',
            component: () => import('../views/order_management/product_order/index.vue'),
            meta: {
              title: '商品订单',
              isHidden: false,
            }
          },
        ]
      },
    ],
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/login/index.vue'),
  },

]
const router = createRouter({
  history: createWebHashHistory(), // 路由模式
  routes, // 路由规则
})

router.beforeEach((to, from, next) => {
  const token = getToken()
  if (token) {
    next()
    if (to.path === '/') document.title = '家政服务管理系统'
    else document.title = to.name
    nprogress.start() // 开始加载进度条
  } else {
    if (to.path === '/login') {
      // 跳转到登录页
      next()
    } else {
      next({ path: '/login' })
    }
  }
})
router.afterEach(() => {
  nprogress.done() // 开始加载进度条
})

export default router
